package cn.doit.scala.day03

/**
 * @DATE 2021/12/27/10:31
 * @Author MDK
 * @Version 2021.2.2
 * */
object C03_Filter {
  def main(args: Array[String]): Unit = {
    val array: Array[Int] = Array[Int](1, 2, 3, 4, 5, 6, 7, 8)
    val ls = List[String]("zss","lss","ny","ly","fjj")
    val mp = Map[String, String]("sl"->"fsy","wd"->"zsf","em"->"zzr","gb"->"qf")

    //直接打印是地址值
//    println(array.filter(_ > 2))
//    println(array.filter(e => e > 5 && e % 2 == 1))
    val res: Array[Int] = array.filter(_ > 2)
    //mkString  foreach都可,不能直接打印
    println(res)

    val res1 = array.filter(e => e % 2 == 0 & e > 5)
    println(s"$res1")

    ls.filter(_.startsWith("z")).foreach(println)
    println("-----------------------------------------")
    val res2: Map[String, String] = mp.filter(tp => tp._2.contains("s"))
    res2.foreach(println)

    println("-----------------------------------------")
    val res3 = for (elem <- array if elem % 2 == 0) yield elem
    println(res3.toList)
    res3.foreach(println)

    println("-----------------------------------------")
    val list = List[Any]("hbase","java","scala",123, 23.1)
    list.filter(e=>e.isInstanceOf[String] || e.isInstanceOf[Int]).foreach(println)
  }
}
